// run: $exec < input
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

int const maxn = 100007;
std::vector<long long> a;
using pair_type = std::pair<long long, long long>;
std::vector<pair_type> b;
int n;

long long dp[maxn];

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) std::cin >> a[i];
	std::sort(a.begin(), a.end());

	pair_type tmp{a[0], 1};
	for (int i = 1; i < n; i++)
		if (a[i] == a[i - 1]) tmp.second++;
		else {
			b.push_back(tmp);
			tmp.first = a[i];
			tmp.second = 1;
		}
	b.push_back(tmp);

	int n = b.size();
	for (int i = 1; i <= n; i++) {
		dp[i] = b[i - 1].first * b[i - 1].second;
		if (b[i - 2].first + 1 == b[i - 1].first) dp[i] += dp[i - 2];
		else dp[i] += dp[i - 1];
		dp[i] = std::max(dp[i], dp[i - 1]);
	}
	std::cout << dp[n] << '\n';
}

